<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        h2,
        p {
            margin: 0;
        }

        .box {
            margin: 30px auto;
            width: 300px;
        }

        #user,
        #message {
            box-sizing: border-box;
            width: 300px;
            border: 1px solid #000;
            padding: 10px;
            height: 100px;
            resize: none;
            display: block;
        }

        #user {
            padding: 0 10px;
            height: 30px;
            margin-bottom: 10px;
        }

        #btn {
            display: block;
            margin: 10px auto;
            width: 60%;
            height: 40px;
        }

        #list {
            border-top: 1px solid #000;
            padding: 10px 0 0;
            margin: 0;
            list-style: none;
        }

        #list li {
            position: relative;
            font: 14px/30px "宋体";
            border-bottom: 1px solid #000;
            padding: 0 15px;
            overflow: hidden;
        }

        .clos {
            position: absolute;
            right: 5px;
            top: 10px;
        }

        .clos2 {
            position: absolute;
            right: 5px;
            top: 30px;
        }

        /* .replay{
    position:absolute;
    right: 5px;
    top: 35px;
} */
        .mask {
            width: 100vw;
            height: 100vh;
            background: black;
            opacity: .3;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }

        .comfirm {
            width: 200px;
            height: 120px;
            background: white;
            text-align: center;
            position: absolute;
            left: 50%;
            top: 30%;
            border-radius: 5px;
            transform: translate(-50%, -50%);
            overflow: hidden;
            display: none;

        }

        .comfirm button {
            /* position: absolute; */
            /* right: 10px; */
            float: right;
            margin-top: 20px;
            margin-right: 10px;
        }

        /* .replay { */
            /* display: none; */
        /* } */
    </style>
    <script src="./vue.js"></script>
</head>

<body>
    <div class="box" id="app">
        <input type="text" id="user" v-model="username" value="小明" />
        <textarea id="message" v-model="content">我就是传说中的无敌小明</textarea>
        <button id="btn" @click="addMessage">提交留言</button>
        <ul id="list">
            <li style="height: auto" v-for="(item,key) in arr" :key="key">
                <h2 class="user">{{item.name}}说:</h2>
                <p>{{item.message}}</p>

                <div class="replay" v-show="item.isshow">
                    <input type="text" v-model="item.inputData" /><button @click="sureAdd(key)">确定</button><button
                        @click="cancelReplay(key)">取消</button>
                </div>
                <p v-for="(val,k) in item.replayData">{{val}}</p>
                <a @click="del(key)" href="javascript:;" class="clos">删除</a>
                <a href="javascript:;" @click="changeReplay(key)" class="clos2">回复</a>

            </li>

        </ul>


    </div>

    <script>
        var arr = [
            {
                name: "小张",
                message: "1111",
                replayData: [
                    "第一条回复内容",
                    "第二条回复内容"
                ]
            },
            {
                name: "小张",
                message: "2222",
                replayData: [
                    "第一条回复内容22",
                    "第二条回复内容22"
                ]
            },
            {
                name: "小张",
                message: "333",
                replayData: [
                    "第一条回复内容33",
                    "第二条回复内容33"
                ]
            }
        ]

        arr.forEach(item => {
            item.isshow = false;
            item.inputData = "";
        })
        // console.log(arr);

        new Vue({
            el: "#app",
            data: {
                // judge:true,
                arr,
                username: "我是小明",
                content: "默认内容"
            },
            methods: {
                del(key) {
                    this.arr.splice(key, 1);
                },
                changeReplay(key) {
                    this.arr[key].isshow = true;
                },
                cancelReplay(key) {
                    this.arr[key].isshow = false;
                },
                sureAdd(key) {
                    // console.log( this.arr[key].inputData);
                    this.arr[key].replayData.push(this.arr[key].inputData);
                    this.arr[key].isshow = false;
                },
                addMessage() {
                    let obj = {
                        name:this.username,
                        message: this.content,
                        replayData: [
                            
                        ],
                        isshow:false,
                        inputData:""
                    }
                    this.arr.push(obj);
                }
            }
        })



    </script>

</body>

</html>